import math

ni = 0
alpha = 15

class Point:
	def __init__(self, x = 0, y = 0):
		self.x = x
		self.y = y
	
	def __str__(self):
		return '(' + str(self.x) + ', ' + str(self.y) + ')'

	def getX(self):
		return self.x
	
	def getY(self):
		return self.y

class BlackBox:
	def calculateCosine(self, point1, point2, point3):
		v1 = [point2.x - point1.x, point2.y - point1.y]
		v2 = [point3.x - point2.x, point3.y - point2.y]
		cos = (v1[0]*v2[0]+v1[1]*v2[1])/(math.sqrt(v1[0]*v1[0]+v1[1]*v1[1])*math.sqrt(v2[0]*v2[0]+v2[1]*v2[1]))
		return cos

	def calculateTime(self, pointList=[]):
		total = 0
		v = 0
		for index in range(0, len(pointList) - 1, 1):
			res = self.calculateTimeForPoint(pointList[index], pointList[index + 1], v)
			if index>0:
				cos = self.calculateCosine(pointList[index-1], pointList[index], pointList[index + 1])
				if cos < 0.95 and cos>0:
					v*=cos
				elif cos <= 0:
					v=0
			total += res[0]
		   # print res
			v = res[1]
		return total

	def calculateTimeForPoint(self, point1, point2, v):
		alpha_radians = math.radians(alpha)
		x = math.fabs(point2.getX() - point1.getX())
		y = math.fabs(point2.getY() - point1.getY());
		beta_radians = math.atan(x / y )

		if point2.getX() > point1.getX() and point2.getY() < point1.getY()  :
			beta_radians = math.pi - math.fabs(beta_radians)
		elif point2.getX() < point1.getX() and point2.getY() > point1.getY():
			beta_radians = 2* math.pi - math.fabs(beta_radians)
		elif point2.getX() < point1.getX() and point2.getY() < point1.getY():
			beta_radians += math.pi;

		distance = math.sqrt(x * x + y * y)
		z = 9.81 * math.cos(alpha_radians) * (math.tan(alpha_radians) * math.fabs(math.cos(beta_radians)) - ni)
		#licznik = -2 * v + math.sqrt(4 * v * v + 8 * z * distance);
		#mianownik = 2 * z;
		t = self.solve(z/2,v,-distance)
		v += (z * t)
		return [t,v];

	def solve(self, a,b,c):
		delta = b*b - 4 * a * c
		x1 = (-b - math.sqrt(delta)) / (2*a)
		x2 = (-b + math.sqrt(delta)) / (2*a)

		if x1 > 0 and x2 > 0:
			return min(x1, x2)
		elif x1 >= 0 or x2 >= 0:
			return max(x1, x2)
		else :
			return 0